﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace FlashCards.SL.Controls
{
    public class Label : System.Windows.Controls.Label
    {
        public static readonly DependencyProperty HeaderProperty;
        public static readonly DependencyProperty HeaderWidthProperty;

        private Grid mainGrid;

        public Label()
        {
            this.DefaultStyleKey = typeof(Label);
        }

        static Label()
        {
            HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(Label), null);
            HeaderWidthProperty = DependencyProperty.Register("HeaderWidth", typeof(double), typeof(Label), null);
        }

        #region CUSTOM CONTROL PROPERTIES

        [Description("The text displayed in the header section"), Category("Common Properties")]
        public string Header
        {
            get { return (string)GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        [Description("Width of the header section"), Category("Common Properties")]
        public double HeaderWidth
        {
            get { return (double)GetValue(HeaderWidthProperty); }
            set { SetValue(HeaderWidthProperty, value); }
        }

        #endregion

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            mainGrid = GetTemplateChild("LayoutRoot") as Grid;
            if (mainGrid != null)
                mainGrid.ColumnDefinitions[0].Width = new GridLength(HeaderWidth);
        }
    }
}
